package com.fuxi.cloud.desreport.service.a;

import cn.hutool.core.codec.Base64;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fuxi.cloud.common.constant.CommonConstant;
import com.fuxi.cloud.common.util.ExcelUtil;
import com.fuxi.cloud.common.util.GoogleBarCodeUtils;
import com.fuxi.cloud.common.util.oConvertUtils;
import com.fuxi.cloud.desreport.entity.JimuReport;
import com.fuxi.cloud.desreport.service.IJmReportExportExcel;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.openxml4j.opc.PackagePartName;
import org.apache.poi.openxml4j.opc.PackageRelationship;
import org.apache.poi.openxml4j.opc.TargetMode;
import org.apache.poi.ss.formula.FormulaParseException;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.RegionUtil;
import org.apache.poi.xssf.usermodel.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * a
 *
 * @Author: 扫地僧
 * @CreateTime: 2021-05-03
 */
@Service("jmReportExportExcelImpl")
public class j implements IJmReportExportExcel {
    private static final Logger a = LoggerFactory.getLogger(j.class);

    public j() {
    }

    @Override
    public Map<String, Object> exportExcel(JimuReport jimuReport, Map<String, String[]> mapReq, List echartBase) {
        JSONObject var4 = JSON.parseObject(jimuReport.getJsonStr());
        XSSFWorkbook var5 = this.a(var4, echartBase);
        String var6 = jimuReport.getName() + (new SimpleDateFormat("yyyyMMddHHmmss")).format(new Date()).toString();
        HashMap var7 = new HashMap();
        var7.put("name", var6 + ".xlsx");
        var7.put("workbook", var5);
        return var7;
    }

    private XSSFWorkbook a(JSONObject var1, List var2) {
        JSONArray var3 = null;
        JSONArray var4 = null;
        JSONArray var5 = null;
        JSONArray var6 = null;
        JSONObject var7 = null;
        if (var1.containsKey("imgList")) {
            var3 = var1.getJSONArray("imgList");
        }

        if (var1.containsKey("chartList")) {
            var4 = var1.getJSONArray("chartList");
        }

        if (var1.containsKey("barcodeList")) {
            var5 = var1.getJSONArray("barcodeList");
        }

        if (var1.containsKey("qrcodeList")) {
            var6 = var1.getJSONArray("qrcodeList");
        }

        if (var1.containsKey("background")) {
            Object var8 = var1.get("background");
            if (var8 instanceof JSONObject) {
                var7 = var1.getJSONObject("background");
            }
        }

        JSONObject var9;
        if (var4 != null && var4.size() > 0 && var2.size() > 0) {
            for(int var21 = 0; var21 < var4.size(); ++var21) {
                var9 = var4.getJSONObject(var21);
                String var10 = (String)var9.get("layer_id");
                List var11 = var2;
                String var12 = "";

                for(int var13 = 0; var13 < var11.size(); ++var13) {
                    Map var14 = (Map)var11.get(var13);
                    if (((String)var14.get("id")).equals(var10)) {
                        var12 = (String)var14.get("base64");
                    }
                }

                String[] var26 = var12.split("base64,");
                var9.put("url", var26[1]);
            }
        }

        XSSFWorkbook var22 = new XSSFWorkbook();
        var9 = var1.getJSONObject("rows");
        JSONObject var23 = var1.getJSONObject("cols");
        if (var23.containsKey("len")) {
            var23.remove("len");
        }

        if (var9.containsKey("-1")) {
            var9.remove("-1");
        }

        String var24 = var1.getString("name");
        Object var25 = var1.get("styles");
        HashMap var27 = new HashMap();
        int var15;
        if (var25 instanceof JSONArray) {
            JSONArray var28 = var1.getJSONArray("styles");

            for(var15 = 0; var15 < var28.size(); ++var15) {
                var27.put(String.valueOf(var15), var28.get(var15));
            }
        }

        if (var25 instanceof JSONObject) {
            JSONObject var29 = (JSONObject)var25;

            for(var15 = 1; var15 <= var29.size(); ++var15) {
                var27.put(String.valueOf(var15), var29.get(var15));
            }
        }

        XSSFSheet var30 = var22.createSheet(var24);
        this.a((Sheet)var30, (JSONObject)var23);
        var30.setDefaultRowHeightInPoints(19.5F);
        HashMap var31 = new HashMap();
        HashMap var16 = new HashMap();
        HashMap var17 = new HashMap();
        ArrayList var18 = new ArrayList();
        HashMap var19 = new HashMap();
        this.a(var22, var9, var27, var30, var31, var16, var17, var18);
        HashMap var20 = new HashMap();
        this.a((JSONObject)var9, var30, (XSSFWorkbook)var22, var27, var20, var19);
        this.a((Sheet)var30, (XSSFWorkbook)var22, (Map)var19);
        this.a((Workbook)var22, var30, (Map)var31, var20, var16, var17);
        if (var3 != null) {
            this.a((Sheet)var30, (XSSFWorkbook)var22, (JSONArray)var3, (Map)var20);
        }

        if (var4 != null) {
            this.a((Sheet)var30, (XSSFWorkbook)var22, (JSONArray)var4);
        }

        if (var5 != null) {
            this.a((Sheet)var30, (Workbook)var22, (JSONArray)var5, (List)var2);
        }

        if (var6 != null) {
            this.a((Sheet)var30, (Workbook)var22, (JSONArray)var6, (List)var2);
        }

        if (var7 != null) {
            this.a((Sheet)var30, (XSSFWorkbook)var22, (JSONObject)var7);
        }

        if (null != var18 && var18.size() > 0) {
            this.a((Sheet)var30, (XSSFWorkbook)var22, (List)var18, (Map)var20);
        }

        return var22;
    }

    private void a(Sheet var1, XSSFWorkbook var2, Map<String, JSONObject> var3) {
        Iterator var4 = var3.keySet().iterator();

        while(true) {
            JSONObject var6;
            String[] var7;
            do {
                if (!var4.hasNext()) {
                    return;
                }

                String var5 = (String)var4.next();
                var6 = JSONObject.parseObject(String.valueOf(var3.get(var5)));
                var7 = var5.split(",");
            } while(var7.length != 4);

            int var8 = Integer.valueOf(var7[0]);
            int var9 = Integer.valueOf(var7[1]);
            int var10 = Integer.valueOf(var7[2]);
            int var11 = Integer.valueOf(var7[3]);

            for(int var12 = var8; var12 < var9 + 1; ++var12) {
                Row var13 = var1.getRow(var12);

                for(int var14 = var10; var14 < var11 + 1; ++var14) {
                    try {
                        Cell var15 = var13.getCell(var14);
                        if (null != var15) {
                            XSSFCellStyle var16 = (XSSFCellStyle)var15.getCellStyle();
                            Object var17 = var6.get("top");
                            Object var18 = var6.get("left");
                            Object var19 = var6.get("right");
                            Object var20 = var6.get("bottom");
                            XSSFColor var21;
                            if (null != var17) {
                                var21 = this.b(var17.toString());
                                var16.setTopBorderColor(var21);
                            }

                            if (null != var18) {
                                var21 = this.b(var18.toString());
                                var16.setLeftBorderColor(var21);
                            }

                            if (null != var19) {
                                var21 = this.b(var19.toString());
                                var16.setRightBorderColor(var21);
                            }

                            if (null != var20) {
                                var21 = this.b(var20.toString());
                                var16.setBottomBorderColor(var21);
                            }

                            var15.setCellStyle(var16);
                        }
                    } catch (NullPointerException var22) {
                        a.debug("单元格为空", var22.getMessage());
                    }
                }
            }
        }
    }

    private void a(XSSFWorkbook var1, JSONObject var2, Map var3, Sheet var4, Map<String, String> var5, Map<String, JSONObject> var6, Map<String, List<String>> var7, List<Map<String, Object>> var8) {
        Iterator var9 = var2.keySet().iterator();

        label125:
        while(true) {
            String var10;
            int var11;
            do {
                do {
                    do {
                        do {
                            if (!var9.hasNext()) {
                                return;
                            }

                            var10 = (String)var9.next();
                        } while("cells".equals(var10));
                    } while("isDrag".equals(var10));
                } while("len".equals(var10));

                var11 = Integer.parseInt(var10);
            } while(var11 < 0);

            Row var12 = var4.createRow(Integer.parseInt(var10));
            if (var2.getJSONObject(var10).containsKey("height")) {
                Integer var13 = var2.getJSONObject(var10).getInteger("height");
                var12.setHeightInPoints((float)var13 - 9.5F);
            }

            JSONObject var29 = var2.getJSONObject(var10).getJSONObject("cells");
            var29 = this.a(var29);
            Iterator var14 = var29.keySet().iterator();

            while(true) {
                while(true) {
                    while(true) {
                        String var15;
                        JSONObject var16;
                        Cell var17;
                        String var18;
                        String var21;
                        do {
                            do {
                                if (!var14.hasNext()) {
                                    continue label125;
                                }

                                var15 = (String)var14.next();
                            } while("-1".equals(var15));

                            var16 = var29.getJSONObject(var15);
                            var17 = var12.createCell(Integer.parseInt(var15));
                            if (var16.containsKey("display")) {
                                var18 = var16.getString("display");
                                if ("barcode".equals(var18) || "qrcode".equals(var18) || "img".equals(var18)) {
                                    HashMap var19 = new HashMap();
                                    String var20 = var16.getString("display");
                                    var21 = var16.getString("text");
                                    String var22 = var16.getString("style");
                                    String var23 = var16.getString("style");
                                    var19.put("style", (JSONObject)var3.get(var23));
                                    var19.put("text", var21);
                                    var19.put("display", var20);
                                    var19.put("row", var17.getRowIndex());
                                    var19.put("cell", var17.getColumnIndex());
                                    var8.add(var19);
                                }
                            }

                            if (var16.containsKey("style")) {
                                this.a(var16, var3, var1, var17);
                            }
                        } while(!var16.containsKey("text"));

                        var18 = var16.getString("text");
                        String var30 = "";

                        try {
                            var30 = this.a(var16, var3, var18);
                        } catch (Exception var28) {
                            var28.printStackTrace();
                        }

                        if (var18.contains("|")) {
                            Object var31 = var16.get("lineStart");
                            if (null != var31) {
                                var5.put(var10 + "," + var15, var31.toString());
                                var21 = var16.getString("style");
                                var6.put(var10 + "," + var15, (JSONObject)var3.get(var21));
                                ArrayList var33 = new ArrayList();
                                var33.add(var10);
                                var33.add(var15);
                                var7.put(var10, var33);
                            }
                        }

                        boolean var32 = var18.matches("^[-+]?(([0-9]+)([.]([0-9]+))?|([.]([0-9]+))?)$");
                        var21 = "^[=]?[A-Z]{1,2}[^\\u4e00-\\u9fa5]+$";
                        Pattern var34 = Pattern.compile(var21);
                        Matcher var35 = var34.matcher(var18);
                        String var24 = var16.getString("style");
                        if (!ExcelUtil.isHave(CommonConstant.JIMUREPORT_FUNCTION, var18) && !var35.matches()) {
                            String var25 = "";
                            if (oConvertUtils.isNotEmpty(var24)) {
                                JSONObject var26 = (JSONObject)var3.get(var24);
                                if (var26.containsKey("format")) {
                                    var25 = var26.getString("format");
                                }
                            }

                            if (oConvertUtils.isNotEmpty(var25) && "number".equals(var25)) {
                                var17.setCellValue(Double.parseDouble(var18));
                            } else {
                                var17.setCellValue(ObjectUtil.isNotEmpty(var30) ? var30 : var18);
                            }
                        } else {
                            try {
                                if (var18.contains("=")) {
                                    var17.setCellFormula(var18.split("=")[1]);
                                } else {
                                    var17.setCellValue(var18);
                                }
                            } catch (FormulaParseException var27) {
                                var17.setCellValue(var18);
                                a.debug("单元格表达式设置失败", var27.getMessage());
                            }
                        }
                    }
                }
            }
        }
    }

    private void a(JSONObject var1, Map var2, XSSFWorkbook var3, Cell var4) {
        if (var1.containsKey("style")) {
            String var5 = var1.getString("style");
            if (var5 != null && !"null".equals(var5)) {
                JSONObject var6 = (JSONObject)var2.get(var5);
                XSSFCellStyle var7 = var3.createCellStyle();
                if (null != var6) {
                    String var8;
                    if (!var6.containsKey("align")) {
                        var7.setAlignment(HorizontalAlignment.LEFT);
                    } else {
                        var8 = var6.getString("align").toUpperCase();
                        var7.setAlignment(HorizontalAlignment.valueOf(var8));
                    }

                    if (null != var6 && !var6.containsKey("valign")) {
                        var7.setVerticalAlignment(VerticalAlignment.valueOf("center".toUpperCase()));
                    } else {
                        var8 = var6.getString("valign").toUpperCase();
                        if ("MIDDLE".equals(var8)) {
                            var8 = "center".toUpperCase();
                        }

                        var7.setVerticalAlignment(VerticalAlignment.valueOf(var8));
                    }

                    if (null == var6 || var6.containsKey("bgcolor")) {
                        var8 = var6.getString("bgcolor");
                        XSSFColor var9 = new XSSFColor();
                        if (var8.indexOf("#") != -1) {
                            byte[] var10 = new byte[]{(byte)Integer.parseInt(var8.substring(1, 3), 16), (byte)Integer.parseInt(var8.substring(3, 5), 16), (byte)Integer.parseInt(var8.substring(5, 7), 16)};
                            var9.setRGB(var10);
                        }

                        var7.setFillForegroundColor(var9);
                        var7.setFillBackgroundColor(var9);
                        var7.setFillPattern(FillPatternType.BIG_SPOTS);
                    }

                    XSSFColor var13;
                    if (null != var6 && var6.containsKey("font") || var6.containsKey("underline") || var6.containsKey("strike") || var6.containsKey("color")) {
                        XSSFFont var17 = var3.createFont();
                        JSONObject var16 = (JSONObject)var6.get("font");
                        Object var20 = var6.get("underline");
                        Object var11 = var6.get("strike");
                        if (null != var16) {
                            if (var16.containsKey("name")) {
                                var17.setFontName(var16.getString("name"));
                            }

                            if (var16.containsKey("italic")) {
                                var17.setItalic(true);
                            }

                            if (var16.containsKey("size")) {
                                var17.setFontHeightInPoints(var16.getShort("size"));
                            }

                            if (var16.containsKey("bold")) {
                                boolean var12 = var16.getBoolean("bold");
                                var17.setBold(var12);
                            }
                        }

                        if (null != var20) {
                            var17.setUnderline((byte)1);
                        }

                        if (null != var11) {
                            var17.setStrikeout(true);
                        }

                        if (null != var6 && var6.containsKey("color")) {
                            String var23 = var6.getString("color");
                            var13 = new XSSFColor();
                            if (var23.length() > 6) {
                                if (var23.contains("rgb")) {
                                    var23 = var23.replace("rgb", "").replace("(", "").replace(")", "");
                                    String[] var14 = var23.split(",");
                                    if (var14.length == 3) {
                                        byte[] var15 = new byte[]{(byte)Integer.parseInt(var14[0]), (byte)Integer.parseInt(var14[1]), (byte)Integer.parseInt(var14[2])};
                                        var13.setRGB(var15);
                                    }
                                } else if (var23.contains("#")) {
                                    byte[] var25 = new byte[]{(byte)Integer.parseInt(var23.substring(1, 3), 16), (byte)Integer.parseInt(var23.substring(3, 5), 16), (byte)Integer.parseInt(var23.substring(5, 7), 16)};
                                    var13.setRGB(var25);
                                }
                            }

                            var17.setColor(var13);
                        }

                        var7.setFont(var17);
                    }

                    if (var6.containsKey("border")) {
                        JSONObject var19 = var6.getJSONObject("border");
                        JSONArray var18 = var19.getJSONArray("right");
                        JSONArray var21 = var19.getJSONArray("top");
                        JSONArray var22 = var19.getJSONArray("left");
                        JSONArray var24 = var19.getJSONArray("bottom");
                        if (null != var21 && var21.size() > 1) {
                            var7.setBorderTop(BorderStyle.THIN);
                            var13 = this.b(var21.get(1).toString());
                            var7.setTopBorderColor(var13);
                        }

                        if (null != var24 && var24.size() > 1) {
                            var7.setBorderBottom(BorderStyle.THIN);
                            var13 = this.b(var24.get(1).toString());
                            var7.setBottomBorderColor(var13);
                        }

                        if (null != var22 && var22.size() > 1) {
                            var7.setBorderLeft(BorderStyle.THIN);
                            var13 = this.b(var22.get(1).toString());
                            var7.setLeftBorderColor(var13);
                        }

                        if (null != var18 && var18.size() > 1) {
                            var7.setBorderRight(BorderStyle.THIN);
                            var13 = this.b(var18.get(1).toString());
                            var7.setRightBorderColor(var13);
                        }
                    }

                    var7.setWrapText(true);
                    var4.setCellStyle(var7);
                }
            }
        }

    }

    private void a(Sheet var1, JSONObject var2) {
        var1.setDefaultColumnWidth(12);
        Iterator var3 = var2.keySet().iterator();

        while(var3.hasNext()) {
            String var4 = (String)var3.next();
            JSONObject var5 = (JSONObject)var2.get(var4);
            var1.setColumnWidth(Integer.parseInt(var4), 35 * (int)((double)var5.getInteger("width") + 0.8D));
        }

    }

    private JSONObject a(JSONObject var1) {
        ArrayList var2 = new ArrayList();
        Iterator var3 = var1.keySet().iterator();

        while(var3.hasNext()) {
            String var4 = (String)var3.next();
            if (oConvertUtils.isNotEmpty(var4) && !"NaN".equals(var4)) {
                var2.add(Integer.parseInt(var4));
            }
        }

        Collections.sort(var2);
        JSONArray var9 = new JSONArray();
        JSONObject var5 = new JSONObject(true);
        Iterator var6 = var2.iterator();

        while(var6.hasNext()) {
            Integer var7 = (Integer)var6.next();
            JSONObject var8 = var1.getJSONObject(String.valueOf(var7));
            var9.add(var8);
            var5.put(String.valueOf(var7), var8);
        }

        return var5;
    }

    private void a(JSONObject var1, Sheet var2, XSSFWorkbook var3, Map var4, Map<String, String> var5, Map<String, JSONObject> var6) {
        Iterator var7 = var1.keySet().iterator();

        while(true) {
            String var8;
            JSONObject var9;
            do {
                do {
                    do {
                        do {
                            if (!var7.hasNext()) {
                                return;
                            }

                            var8 = (String)var7.next();
                        } while("len".equals(var8));
                    } while("cells".equals(var8));
                } while("isDrag".equals(var8));

                var9 = var1.getJSONObject(var8).getJSONObject("cells");
            } while(null == var9);

            Iterator var10 = var9.keySet().iterator();

            while(var10.hasNext()) {
                String var11 = (String)var10.next();
                JSONObject var12 = var9.getJSONObject(var11);
                if (var12.containsKey("merge")) {
                    String var13 = var12.getString("merge");
                    String[] var14 = a(var13, "[", "]").split(",");
                    int var15 = Integer.parseInt(var14[0]);
                    int var16 = Integer.parseInt(var14[1]);
                    if (var13 != null && !"".equals(var13)) {
                        JSONObject var17 = new JSONObject();
                        int var18 = Integer.parseInt(var8);
                        int var19 = var15 + var18;
                        int var20 = Integer.parseInt(var11);
                        int var21 = var16 + var20;
                        CellRangeAddress var22 = new CellRangeAddress(var18, var19, var20, var21);

                        try {
                            var2.addMergedRegion(var22);
                        } catch (IllegalArgumentException var31) {
                            a.info("合并单元格失败，原因：已重复或单个单元格不允许合并");
                        }

                        var5.put(var18 + "," + var20, var19 + "," + var21);
                        if (var12.containsKey("style")) {
                            String var23 = var12.getString("style");
                            JSONObject var24 = (JSONObject)var4.get(var23);
                            if (null != var24 && var24.containsKey("border")) {
                                JSONObject var25 = var24.getJSONObject("border");
                                Iterator var26 = var25.keySet().iterator();
                                JSONArray var27 = var25.getJSONArray("right");
                                JSONArray var28 = var25.getJSONArray("top");
                                if (null != var28 && var28.size() > 1) {
                                    RegionUtil.setBorderTop(BorderStyle.THIN, var22, var2);
                                    var17.put("top", var28.get(1).toString());
                                }

                                if (null != var27 && var27.size() > 1) {
                                    RegionUtil.setBorderRight(BorderStyle.THIN, var22, var2);
                                    var17.put("right", var27.get(1).toString());
                                }

                                JSONArray var29 = var25.getJSONArray("left");
                                if (null != var29 && var29.size() > 1) {
                                    RegionUtil.setBorderLeft(BorderStyle.THIN, var22, var2);
                                    var17.put("left", var29.get(1).toString());
                                }

                                JSONArray var30 = var25.getJSONArray("bottom");
                                if (null != var30 && var30.size() > 1) {
                                    RegionUtil.setBorderBottom(BorderStyle.THIN, var22, var2);
                                    var17.put("bottom", var30.get(1).toString());
                                }
                            }

                            String var32 = var18 + "," + var19 + "," + var20 + "," + var21;
                            var6.put(var32, var17);
                        }
                    }
                }
            }
        }
    }

    public static String a(String var0, String var1, String var2) {
        int var3 = var0.indexOf(var1);
        int var4 = var0.indexOf(var2);
        if (var3 < 0) {
            return "";
        } else if (var4 < 0) {
            return "";
        } else {
            String var5 = var0.substring(var3, var4).substring(var1.length());
            return var5;
        }
    }

    private void a(Sheet var1, XSSFWorkbook var2, JSONArray var3, Map<String, String> var4) {
        XSSFDrawing var5 = (XSSFDrawing)var1.createDrawingPatriarch();
        HttpURLConnection var6 = null;

        try {
            for(int var8 = 0; var8 < var3.size(); ++var8) {
                boolean var9 = false;
                boolean var10 = false;
                String var11 = "";
                String var12 = "";
                String var13 = "";
                JSONObject var14 = var3.getJSONObject(var8);
                int var34 = Integer.valueOf(var14.getString("col"));
                int var33 = Integer.valueOf(var14.getString("row"));
                var12 = (String)var14.get("width");
                var13 = (String)var14.get("height");
                var11 = (String)var14.get("src");
                if (var13.contains("px") && var12.contains("px")) {
                    var13 = var13.substring(0, var13.lastIndexOf("px"));
                    var12 = var12.substring(0, var12.lastIndexOf("px"));
                }

                URL var15 = new URL(var11);
                byte[] var7;
                if (var11.contains("https")) {
                    var7 = com.fuxi.cloud.desreport.b.a.a(var11);
                } else {
                    var6 = (HttpURLConnection)var15.openConnection();
                    var6.setRequestMethod("GET");
                    var6.setConnectTimeout(50000);
                    InputStream var16 = var6.getInputStream();
                    var7 = a(var16);
                }

                String var35 = (String)var4.get(var33 + "," + var34);
                boolean var17 = false;
                int var36;
                if (oConvertUtils.isNotEmpty(var35)) {
                    String var18 = var35.split(",")[0];
                    var36 = Integer.parseInt(var18);
                } else {
                    var36 = var33 + Integer.parseInt(String.format("%.0f", Float.parseFloat(var13) / 25.0F));
                }

                Integer var37 = this.a(var1, var33, (float)Integer.parseInt(var13));
                if (var37 > 0) {
                    var36 = var37;
                } else {
                    var36 += var33;
                }

                int var19 = Integer.parseInt(String.format("%.0f", Float.parseFloat(var12) / 100.0F));
                Object var20 = var14.get("isBackendImg");
                if (null != var20 && (Boolean)var20) {
                    int var38 = var2.addPicture(var7, 6);
                    XSSFPictureData var22 = (XSSFPictureData)var2.getAllPictures().get(var38);

                    try {
                        for(int var23 = 0; var23 < var2.getNumberOfSheets(); ++var23) {
                            XSSFSheet var39 = var2.getSheetAt(var23);
                            PackagePartName var25 = var22.getPackagePart().getPartName();
                            String var26 = XSSFRelation.IMAGES.getRelation();
                            PackageRelationship var27 = var39.getPackagePart().addRelationship(var25, TargetMode.EXTERNAL, var26, (String)null);
                            var39.getCTWorksheet().addNewPicture().setId(var27.getId());
                        }
                    } catch (Exception var28) {
                        XSSFClientAnchor var24 = new XSSFClientAnchor(0, 0, Integer.parseInt(var12), Integer.parseInt(var13), var34, var33, var34 + var19, var36);
                        var5.createPicture(var24, var2.addPicture(var7, 5));
                    }
                } else {
                    XSSFClientAnchor var21 = new XSSFClientAnchor(0, 0, Integer.parseInt(var12), Integer.parseInt(var13), var34, var33, var34 + var19, var36);
                    var5.createPicture(var21, var2.addPicture(var7, 5));
                }
            }
        } catch (MalformedURLException var29) {
            var29.printStackTrace();
        } catch (ProtocolException var30) {
            var30.printStackTrace();
        } catch (IOException var31) {
            var31.printStackTrace();
        } catch (Exception var32) {
            var32.printStackTrace();
        }

    }

    private void a(Sheet var1, XSSFWorkbook var2, JSONObject var3) {
        XSSFDrawing var4 = (XSSFDrawing)var1.createDrawingPatriarch();
        Object var5 = null;
        String var6 = "";
        String var7 = "";
        String var8 = "";
        Object var18 = var3.get("width");
        Object var19 = var3.get("height");
        var6 = var3.getString("path");
        byte[] var9 = this.a(var6);
        XSSFPictureData var10 = null;
        boolean var11 = false;

        try {
            int var20 = var2.addPicture(var9, 6);
            var10 = (XSSFPictureData)var2.getAllPictures().get(var20);
        } catch (NullPointerException var17) {
            a.debug("数据为空", var17.getMessage());
        }

        if (var10 != null) {
            for(int var12 = 0; var12 < var2.getNumberOfSheets(); ++var12) {
                XSSFSheet var13 = var2.getSheetAt(var12);
                PackagePartName var14 = var10.getPackagePart().getPartName();
                String var15 = XSSFRelation.IMAGES.getRelation();
                PackageRelationship var16 = var13.getPackagePart().addRelationship(var14, TargetMode.EXTERNAL, var15, (String)null);
                var13.getCTWorksheet().addNewPicture().setId(var16.getId());
            }
        }

    }

    private void a(Sheet var1, XSSFWorkbook var2, JSONArray var3) {
        XSSFDrawing var4 = (XSSFDrawing)var1.createDrawingPatriarch();
        Object var5 = null;

        try {
            for(int var6 = 0; var6 < var3.size(); ++var6) {
                boolean var7 = false;
                boolean var8 = false;
                String var9 = "";
                String var10 = "";
                String var11 = "";
                JSONObject var12 = var3.getJSONObject(var6);
                int var21 = Integer.valueOf(var12.getString("col"));
                int var20 = Integer.valueOf(var12.getString("row"));
                var10 = (String)var12.get("width");
                var11 = (String)var12.get("height");
                var9 = (String)var12.get("url");
                byte[] var13 = new byte[0];
                var13 = Base64.decode(var9);
                int var15 = 0;
                float var16 = Float.parseFloat(var11);

                int var17;
                for(var17 = var20; var17 < var20 + 99; ++var17) {
                    Row var18 = var1.getRow(var17);
                    if (var18 == null) {
                        break;
                    }

                    ++var15;
                    var16 -= var18.getHeightInPoints();
                }

                var15 += Integer.parseInt(String.format("%.0f", var16 / 25.0F));
                var17 = Integer.parseInt(String.format("%.0f", Float.parseFloat(var10) / 100.0F));
                XSSFClientAnchor var22 = new XSSFClientAnchor(0, 0, Integer.parseInt(var10), Integer.parseInt(var11), var21, var20, var21 + var17, var20 + var15);
                var4.createPicture(var22, var2.addPicture(var13, 5)).resize(1.0D);
            }
        } catch (Exception var19) {
            var19.printStackTrace();
        }

    }

    private void a(Sheet var1, Workbook var2, JSONArray var3, List var4) {
        XSSFDrawing var5 = (XSSFDrawing)var1.createDrawingPatriarch();

        for(int var6 = 0; var6 < var3.size(); ++var6) {
            JSONObject var7 = var3.getJSONObject(var6);
            boolean var8 = false;
            boolean var9 = false;
            String var10 = "";
            String var11 = "";
            int var23 = Integer.valueOf(var7.getString("col"));
            int var22 = Integer.valueOf(var7.getString("row"));
            var10 = String.valueOf(var7.get("width"));
            var11 = String.valueOf(var7.get("height"));
            String var12 = (String)var7.get("layer_id");
            String var13 = "";

            for(int var14 = 0; var14 < var4.size(); ++var14) {
                Map var15 = (Map)var4.get(var14);
                Object var16 = var15.get("id");
                if (var12.equals(var16.toString())) {
                    var13 = (String)var15.get("base64");
                }
            }

            byte[] var24 = new byte[0];
            var24 = Base64.decode(var13.replace("data:image/png;base64,", ""));
            float var25 = Float.parseFloat(var11);
            Integer var17 = this.a(var1, var22, var25);
            Integer var18 = this.a(var1, var22, var23, Float.parseFloat(var10));
            if (var18 != 0 && var17 != 0) {
                XSSFClientAnchor var26 = new XSSFClientAnchor(0, 0, Integer.parseInt(var10), Integer.parseInt(var11), var23, var22, var18 + 1, var17);
                var5.createPicture(var26, var2.addPicture(var24, 5));
            } else {
                int var19 = var22 + Integer.parseInt(String.format("%.0f", Float.parseFloat(var11) / 25.0F));
                int var20 = Integer.parseInt(String.format("%.0f", Float.parseFloat(var10) / 100.0F));
                XSSFClientAnchor var21 = new XSSFClientAnchor(0, 0, Integer.parseInt(var10), Integer.parseInt(var11), var23, var22, var23 + var20, var6 + var19);
                var5.createPicture(var21, var2.addPicture(var24, 5));
            }
        }

    }

    private static byte[] a(InputStream var0) throws Exception {
        ByteArrayOutputStream var1 = new ByteArrayOutputStream();
        byte[] var2 = new byte[1024];
        boolean var3 = false;

        int var4;
        while((var4 = var0.read(var2)) != -1) {
            var1.write(var2, 0, var4);
        }

        var0.close();
        return var1.toByteArray();
    }

    public Integer a(Sheet var1, Integer var2, float var3) {
        int var4 = 0;
        Double var5 = 0.0D;

        for(Iterator var6 = var1.iterator(); var6.hasNext(); ++var4) {
            Row var7 = (Row)var6.next();
            if (var2 <= var4) {
                var5 = var5 + (double)var7.getHeightInPoints();
            }

            if (var5 != 0.0D && (double)var3 - var5 <= 10.0D && var4 > 0) {
                return var4;
            }

            if (var5 >= (double)var3 && var4 > 0) {
                return var4;
            }
        }

        return 0;
    }

    public Integer a(Sheet var1, Integer var2, Integer var3, float var4) {
        float var5 = 0.0F;
        Row var6 = var1.getRow(var2);
        Iterator var7 = var6.iterator();

        while(var7.hasNext()) {
            Cell var8 = (Cell)var7.next();
            if (var8.getColumnIndex() >= var3) {
                float var9 = var1.getColumnWidthInPixels(var8.getColumnIndex());
                var5 += var9;
                if (var5 >= var4) {
                    return var8.getColumnIndex();
                }

                float var10 = var4 - var5;
                if (var10 < 30.0F) {
                    return var8.getColumnIndex();
                }
            }
        }

        return 0;
    }

    public String a(JSONObject var1, Map var2, String var3) throws Exception {
        String var4 = var1.getString("style");
        JSONObject var5 = (JSONObject)var2.get(var4);
        if (null != var5 && var4 != null && !"null".equals(var4)) {
            Object var6 = var5.get("format");
            if (null != var6) {
                SimpleDateFormat var7 = ExcelUtil.getFormat(var6.toString());
                if (null != var7 && ObjectUtil.isNotEmpty(var3)) {
                    SimpleDateFormat var8 = ExcelUtil.getDataFormat(var3);
                    if (null != var8) {
                        Date var9 = var8.parse(var3);

                        try {
                            String var10 = var7.format(var9);
                            a.info("日期格式化之后的文本：" + var10);
                            return var10;
                        } catch (Exception var11) {
                            a.info("日期格式不正确：" + var11.getMessage());
                        }
                    }
                }
            }
        }

        return "";
    }

    private void a(Workbook var1, Sheet var2, Map<String, String> var3, Map<String, String> var4, Map<String, JSONObject> var5, Map<String, List<String>> var6) {
        Set var7 = var6.keySet();
        Iterator var8 = var7.iterator();

        while(true) {
            String var11;
            String var12;
            Cell var13;
            String var14;
            String var15;
            String var16;
            JSONObject var17;
            Row var18;
            int var19;
            int var20;
            do {
                do {
                    if (!var8.hasNext()) {
                        return;
                    }

                    String var9 = (String)var8.next();
                    List var10 = (List)var6.get(var9);
                    var11 = (String)var10.get(0);
                    var12 = (String)var10.get(1);
                    var13 = var2.getRow(Integer.parseInt(var11)).getCell(Integer.parseInt(var12));
                    var14 = ExcelUtil.getCellValueByCell(var13);
                } while(!var14.contains("|"));

                var15 = (String)var3.get(var13.getRowIndex() + "," + var13.getColumnIndex());
                var16 = (String)var4.get(var13.getRowIndex() + "," + var13.getColumnIndex());
                var17 = (JSONObject)var5.get(var13.getRowIndex() + "," + var13.getColumnIndex());
                var18 = var2.getRow(Integer.parseInt(var11));
                var19 = (int)var13.getSheet().getColumnWidthInPixels(var13.getColumnIndex());
                var20 = (int)var18.getHeightInPoints();
            } while(!ObjectUtil.isNotEmpty(var15));

            int var21 = 0;
            int var22 = 0;
            int var23 = Integer.parseInt(var11);
            int var24 = Integer.parseInt(var12);
            if (ObjectUtil.isNotEmpty(var16)) {
                String[] var25 = var16.split(",");
                int var26 = Integer.parseInt(var25[0]);
                int var27 = Integer.parseInt(var25[1]);
                var23 = var26;
                var24 = var27;

                int var28;
                for(var28 = var18.getRowNum() + 1; var28 < var26 + 1; ++var28) {
                    Row var29 = var2.getRow(var28);
                    if (var29 != null) {
                        var22 += (int)var2.getRow(var28).getHeightInPoints();
                    }
                }

                for(var28 = var13.getColumnIndex() + 1; var28 < var27 + 1; ++var28) {
                    var21 += (int)var2.getColumnWidthInPixels(var28);
                }
            }

            var19 += var21;
            var20 += var22;
            var13.setCellValue("");

            try {
                a(var14, var1, var2, var19, var20, var15, Integer.parseInt(var11), Integer.parseInt(var12), var23 + 1, var24 + 1, var17);
            } catch (Exception var30) {
                var30.printStackTrace();
            }
        }
    }

    public static void a(String var0, Workbook var1, Sheet var2, int var3, int var4, String var5, int var6, int var7, int var8, int var9, JSONObject var10) {
        String[] var11 = var0.split("\\|");
        int var12 = var11.length;
        Cell var13 = var2.getRow(var6).getCell(var7);
        CellStyle var14 = var13.getCellStyle();
        var14.setWrapText(true);
        Font var15 = var1.getFontAt(var14.getFontIndex());
        var15.setFontName("Microsoft YaHei");
        var15.setFontHeightInPoints((short)10);
        CreationHelper var16 = var1.getCreationHelper();
        String var17 = "";
        if (null != var10 && var10.containsKey("color")) {
            var17 = var10.getString("color");
        }

        String var18;
        if (var5.equals("lefttop")) {
            var18 = a(var11, var3, var4);
            var13.setCellValue(var18);
            Drawing var19 = var2.createDrawingPatriarch();
            if (var11.length == 2) {
                ExcelUtil.paintLine(var19, var19.createAnchor(0, 0, 0, 0, var7, var6, var9, var8), var5, var17);
            } else if (var11.length == 3) {
                ExcelUtil.paintLine(var19, var19.createAnchor(0, 0, 0, -((int)((double)var4 / 2.5D)) * 12700, var7, var6, var9, var8), var5, var17);
                ExcelUtil.paintLine(var19, var19.createAnchor(0, 0, -var3 / 4 * 12700, 0, var7, var6, var9, var8), var5, var17);
            }
        } else {
            var18 = b(var11, var3, var4);
            var13.setCellValue(var18);
            a(var2, var16, var7, var6, var9, var8, var4, var3, var12 - 1, var5, var17);
        }

        var14.setFont(var15);
        var13.setCellStyle(var14);
    }

    public static String a(String[] var0, int var1, int var2) {
        int var3 = var0.length;
        if (var3 < 1 && var3 > 3) {
            return "";
        } else {
            int var4 = var1 / 4;
            if (var3 == 2) {
                var4 -= var0[1].length();
                if (var1 < 150) {
                    var4 -= var0[1].length() * 3;
                }
            } else {
                if (var1 < 186) {
                    var4 -= var0[2].length();
                }

                if (var1 < 160) {
                    if (var0[2].length() == 2) {
                        var4 -= var0[2].length() * 2;
                    } else if (var0[2].length() > 2) {
                        var4 -= var0[2].length();
                    }
                }

                var4 -= var0[2].length();
                if (var0[2].length() > 3) {
                    var4 -= var0[2].length();
                }
            }

            String var5 = "";

            int var6;
            for(var6 = 0; var6 < var4; ++var6) {
                var5 = var5 + " ";
            }

            var6 = var2 / 20;
            if (var3 == 2) {
                var5 = var5 + var0[1];
            } else {
                var5 = var5 + var0[2];
            }

            int var7;
            for(var7 = 0; var7 < var6; ++var7) {
                var5 = var5 + "\n";
            }

            if (var3 == 2) {
                var5 = var5 + var0[0];
            }

            if (var3 == 3) {
                var5 = var5 + var0[0];
                var7 = var1 / 4;
                if (var1 < 270) {
                    var7 = var7 - var0[0].length() * 2 - var0[1].length() * 2;
                }

                if (var1 < 160) {
                    var7 = var7 - var0[0].length() - var0[1].length();
                }

                var7 = var7 - var0[0].length() - var0[1].length();
                if (var0[0].length() > 3) {
                    var7 -= var0[0].length();
                }

                if (var0[1].length() > 3) {
                    if (var1 > 270) {
                        var7 -= var0[1].length() * 2;
                    } else {
                        var7 -= var0[1].length();
                    }
                }

                String var8 = "";

                for(int var9 = 0; var9 < var7; ++var9) {
                    var8 = var8 + " ";
                }

                var5 = var5 + var8 + var0[1];
            }

            return var5;
        }
    }

    public static String b(String[] var0, int var1, int var2) {
        int var3 = var0.length;
        if (var3 < 1 && var3 > 3) {
            return "";
        } else {
            int var4 = var1 / 4;
            if (var3 == 2) {
                var4 -= var0[1].length();
                if (var1 < 240) {
                    if (var0[1].length() > 3) {
                        var4 -= var0[1].length();
                    }

                    var4 -= var0[1].length();
                }
            } else {
                if (var1 < 240) {
                    if (var0[2].length() > 3) {
                        var4 -= var0[2].length();
                    }

                    var4 -= var0[2].length();
                }

                var4 -= var0[2].length();
            }

            String var5 = "";
            int var6 = var2 / 20;
            var5 = var5 + var0[0];
            int var7;
            if (var3 == 2) {
                for(var7 = 0; var7 < var6; ++var7) {
                    var5 = var5 + "\n";
                }

                for(var7 = 0; var7 < var4; ++var7) {
                    var5 = var5 + " ";
                }

                var5 = var5 + var0[1];
            }

            if (var3 == 3) {
                var7 = var1 / 4;
                var7 = var7 - var0[0].length() * 2 - var0[1].length() * 2;
                if (var1 < 150) {
                    var7 = var7 - var0[0].length() * 2 - var0[1].length() * 2;
                }

                if (var0[1].length() > 2) {
                    if (var1 < 260) {
                        var7 -= var0[1].length();
                    }

                    var7 -= var0[1].length();
                }

                if (var0[0].length() > 3) {
                    var7 -= var0[0].length();
                }

                String var8 = " ";

                int var9;
                for(var9 = 0; var9 < var7; ++var9) {
                    var8 = var8 + " ";
                }

                var5 = var5 + var8 + var0[1];

                for(var9 = 0; var9 < var6; ++var9) {
                    var5 = var5 + "\n";
                }

                for(var9 = 0; var9 < var7; ++var9) {
                    var5 = var5 + " ";
                }

                var5 = var5 + var0[2];
            }

            return var5;
        }
    }

    public static void a(Sheet var0, CreationHelper var1, int var2, int var3, int var4, int var5, int var6, int var7, int var8, String var9, String var10) {
        Drawing var11;
        ClientAnchor var12;
        if (var8 == 1) {
            var11 = var0.createDrawingPatriarch();
            var12 = var1.createClientAnchor();
            var12.setCol1(var2);
            var12.setRow1(var3);
            var12.setCol2(var4);
            var12.setRow2(var5);
            ExcelUtil.paintLine(var11, var12, var9, var10);
        } else if (var8 == 2) {
            var11 = var0.createDrawingPatriarch();
            var12 = var1.createClientAnchor();
            var12.setCol1(var2);
            var12.setRow1(var3);
            var12.setCol2(var4);
            var12.setRow2(var5);
            var12.setDx2(-var7 / 4 * 12700);
            ExcelUtil.paintLine(var11, var12, var9, var10);
            ClientAnchor var13 = var1.createClientAnchor();
            Drawing var14 = var0.createDrawingPatriarch();
            var13.setCol1(var2);
            var13.setRow1(var3);
            var13.setCol2(var4);
            var13.setRow2(var5);
            var13.setDy1((int)((double)var6 / 2.5D) * 12700);
            ExcelUtil.paintLine(var14, var13, var9, var10);
        }

    }

    private void a(Sheet var1, XSSFWorkbook var2, List<Map<String, Object>> var3, Map<String, String> var4) {
        XSSFDrawing var5 = (XSSFDrawing)var1.createDrawingPatriarch();

        for(int var6 = 0; var6 < var3.size(); ++var6) {
            Map var7 = (Map)var3.get(var6);
            boolean var8 = false;
            boolean var9 = false;
            int var20 = Integer.valueOf(var7.get("cell").toString());
            int var19 = Integer.valueOf(var7.get("row").toString());
            String var10 = var7.get("text").toString();
            String var11 = var7.get("display").toString();
            Map var12 = this.a(var1, var4, var19, var20);
            Integer var13 = (Integer)var12.get("width");
            Integer var14 = (Integer)var12.get("height");
            Object var15 = null;
            byte[] var21;
            if ("img".equals(var11)) {
                var21 = this.a(var10);
            } else {
                var21 = GoogleBarCodeUtils.createCodeToFile(var10, var11, var13, var14);
            }

            String var16 = (String)var4.get(var19 + "," + var20);
            if (StringUtils.isNotEmpty(var16)) {
                String[] var17 = var16.split(",");
                XSSFClientAnchor var18 = new XSSFClientAnchor(0, 0, var13, var14, var20, var19, Integer.parseInt(var17[1]) + 1, Integer.parseInt(var17[0]) + 1);
                var5.createPicture(var18, var2.addPicture(var21, 5));
            } else {
                XSSFClientAnchor var22 = new XSSFClientAnchor(0, 0, var13, var14, var20, var19, var20 + 1, var19 + 1);
                var5.createPicture(var22, var2.addPicture(var21, 5));
            }
        }

    }

    public byte[] a(String var1) {
        URL var2 = null;

        try {
            var2 = new URL(var1);
            Object var3 = null;
            byte[] var7;
            if (var1.contains("https")) {
                var7 = com.fuxi.cloud.desreport.b.a.a(var1);
                return var7;
            } else {
                HttpURLConnection var4 = null;
                var4 = (HttpURLConnection)var2.openConnection();
                var4.setRequestMethod("GET");
                var4.setConnectTimeout(50000);
                InputStream var5 = var4.getInputStream();
                var7 = a(var5);
                return var7;
            }
        } catch (Exception var6) {
            var6.printStackTrace();
            return null;
        }
    }

    public Map<String, Integer> a(Sheet var1, Map<String, String> var2, Integer var3, Integer var4) {
        HashMap var5 = new HashMap();
        String var6 = (String)var2.get(var3 + "," + var4);
        Row var7 = var1.getRow(var3);
        Cell var8 = var7.getCell(var4);
        var8.setCellValue("");
        int var9 = (int)var8.getSheet().getColumnWidthInPixels(var8.getColumnIndex());
        int var10 = (int)var7.getHeightInPoints();
        int var11 = 0;
        int var12 = 0;
        int var13 = var3;
        int var14 = var4;
        if (ObjectUtil.isNotEmpty(var6)) {
            String[] var15 = var6.split(",");
            int var16 = Integer.parseInt(var15[0]);
            int var17 = Integer.parseInt(var15[1]);

            int var18;
            for(var18 = var7.getRowNum() + 1; var18 < var16 + 1; ++var18) {
                Row var19 = var1.getRow(var18);
                if (var19 != null) {
                    var12 += (int)var1.getRow(var18).getHeightInPoints();
                }
            }

            for(var18 = var8.getColumnIndex() + 1; var18 < var17 + 1; ++var18) {
                var11 += (int)var1.getColumnWidthInPixels(var18);
            }
        }

        var9 += var11;
        var10 += var12;
        var5.put("width", var9);
        var5.put("height", var10);
        return var5;
    }

    public XSSFColor b(String var1) {
        XSSFColor var2 = new XSSFColor();
        if (var1.contains("rgb")) {
            var1 = var1.replace("rgb", "").replace("(", "").replace(")", "");
            String[] var3 = var1.split(",");
            if (var3.length == 3) {
                byte[] var4 = new byte[]{(byte)Integer.parseInt(var3[0]), (byte)Integer.parseInt(var3[1]), (byte)Integer.parseInt(var3[2])};
                var2.setRGB(var4);
            }
        } else if (var1.contains("#") && var1.length() > 6) {
            byte[] var5 = new byte[]{(byte)Integer.parseInt(var1.substring(1, 3), 16), (byte)Integer.parseInt(var1.substring(3, 5), 16), (byte)Integer.parseInt(var1.substring(5, 7), 16)};
            var2.setRGB(var5);
        }

        return var2;
    }
}